package com.king.hrmsdev.service;


import com.king.hrmsdev.entity.Reward;
import com.king.hrmsdev.mapper.RewardMapper;
import com.king.hrmsdev.pojo.Vrewardinfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther:SnakeKing
 * @Date: 2019-09-22
 * @Description: com.king.hrmsdev.service
 * @version:1.0
 */
@Service
public class RewardService {
    @Resource
    private RewardMapper rewardMapper;

    public List<Vrewardinfo> Findallreward() {
        List<Vrewardinfo> vrewardinfoList = rewardMapper.Findallreward();
        return vrewardinfoList;
    }

    public int Insertreward(Reward reward) {
        Map map = new HashMap();
        map.put("job_id", reward.getJob_id());
        map.put("checktime", reward.getChecktime());
        Reward moreone = rewardMapper.checkmore(map);
        if(moreone!=null){
            return 1;
        }

        int flag = 1;
        try {
            rewardMapper.Insertreward(reward);
        } catch (Exception e) {
            flag = 0;
        } finally {
            return flag;
        }
    }

    public int Updatereward(Reward reward) {

        int flag = 1;
        try {

            rewardMapper.Updatereward(reward);
        } catch (Exception e) {
            flag = 0;
        } finally {
            return flag;
        }

    }

    public int deletereward(int reward_id) {
        int flag = 1;
        try {
            rewardMapper.deletereward(reward_id);
        } catch (Exception e) {
            flag = 0;
        } finally {
            return flag;
        }

    }


    public List<Vrewardinfo> RewardFuzzyreward(Map<String, Object> map) {
        Integer job_id = (Integer) map.get("job_id");
        Integer reward_id = (Integer) map.get("reward_id");
        String ename = (String) map.get("ename");
        Object beginDate = map.get("beginDate");
        Object endDate = map.get("endDate");


        Map map1 = new HashMap();

        map1.put("job_id", job_id);
        map1.put("reward_id", reward_id);
        map1.put("ename", ename);
        map1.put("beginDate", beginDate);
        map1.put("endDate", endDate);

        List list = rewardMapper.RewardFuzzyreward(map1);

        return list;

    }

}
